package com.weicai.hive.udf;

import com.weicai.caesar.CaesarUtil;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;


public class CaesarDecodeUDF extends UDF {

    public Text evaluate(String str) {
        if (str == null || str.isEmpty()) {
            return null;
        }
        Text text = new Text("");
        String val = str;
        if (CaesarUtil.isEncrypted(str)){
            val = CaesarUtil.decode(str);
        }
        text.set(val);
        return text;
    }

    public static void main(String[] args) {
        Text a = new CaesarDecodeUDF().evaluate("2YaZT/AlO4Hi5pNgfIEn6WKRKcpH7r6S7qQvjoQ0RGU=");
        System.out.println(a);
    }
}